<?php
/**
 * tpshop
 * $Author: 唐科技 2016-12-12
 */ 
namespace Mobile\Controller;
class AdultController extends MobileBaseController {
	//成人高考首页
	public function ckindex(){
		//6所置顶的学校列表
		$schoolTop=M('article_xueli')->field('id,title,subtitle,thumb,hot')->where(array('second_column_id'=>4,'top'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(6)->select();
		$this->assign(array('schoolTop'=>$schoolTop));
		//2级专业栏目下的3级栏目并文章
		$majorList=M('third_column')->where(array('second_column_id'=>5,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->select();
		foreach($majorList as $k=>$v){
			$majorList[$k]['article']=M('article_xueli')->field('id,title,subtitle,hot')->where(array('third_column_id'=>$v['id'],"top"=>1,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(12)->select();
		}
		$this->assign(array('majorList'=>$majorList));
		//成人高考置顶文章
		$adultList=M('article_xueli')->field('id,title,subtitle,thumb,hot')->where(array('second_column_id'=>1,'top'=>2,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(11)->select();
		$this->assign(array('adultList'=>$adultList));
		//2级栏目下的面试求职文章列表
		$getJob=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>8,"top"=>1,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(5)->select();
		//2级栏目下的职位晋升文章列表
		$heightJob=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>9,"top"=>1,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(5)->select();
		//2级栏目下的复习辅导3级分类文章列表
		$reviewSon=M('third_column')->where(array('second_column_id'=>7))->getField('id',true);
		$reviewList=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('third_column_id'=>array('IN',$reviewSon),"top"=>1,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(5)->select();
		//2级栏目下的成考专题文章列表
		$seminarList=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>6,"top"=>1,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(5)->select();
		$this->assign(array('getJob'=>$getJob,'heightJob'=>$heightJob,'reviewList'=>$reviewList,'seminarList'=>$seminarList));		
        $this->display();
    }
	//搜索提交的方法
	public function search(){
		$keyword=I('post.keyword/s','');
		$url=U("Mobile/Adult/lists",array('type'=>5,'keyword'=>$keyword));
		header("Location:{$url}");
	}


	//成人高考的文章页面
	public function article(){
		$id=I('get.id/d',0);
		$article=$this->checkAid($id);	
		if(!$article){
			//如果文章不存在跳到成人高考最火的文章页
			$goId=M('article_xueli')->where(array('second_column_id'=>1,'top'=>2,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(1)->getField('id');
			header("Location:".U('article',array('id'=>$goId)));
		}
		//推荐阅读文章列表
		$remendList=M('article_xueli')->field('id,title,subtitle,publish_time,thumb')->where(array('second_column_id'=>1,'display'=>1))->order(array('click'=>'desc'))->limit(5)->select();
		$this->assign(array('article'=>$article,'remendList'=>$remendList));
		//点击量自增1
		M('article_xueli')->where(array('id'=>$id))->setInc('click',1);
		$this->display();
	}
	//成人高考的检测文章id参数
	public function checkAid($id){
		$article=M('article_xueli')->where(array('id'=>$id,'display'=>1))->find();
		return $article;
	}
	
	
	//成人高考栏目下的学院列表页
	public function school(){
		//热门院校5个文章列表
		$hotSchool=M('article_xueli')->field('xl_article_xueli.id,title,subtitle,thumb,hot,province_id,name')
			->join('xl_region2 ON xl_article_xueli.province_id = xl_region2.id')->where(array('third_column_id'=>1,'top'=>1,'title'=>array('like',array('%大学','%学院'),'OR')))->order(array('order'=>'desc','id'=>'asc'))->limit(5)->select();
//			print_r($hotSchool);die;
		$this->assign(array('hotSchool'=>$hotSchool));
		//所有的省份列表
		$provinceList=M('region2')->where(array('level'=>1,'display'=>1))->select();
		//省份下面的大学文章列表
		for($i=0;$i<10;$i++){
			$provinceList[$i]['article']=M('article_xueli')->field('id,title,subtitle,hot')->where(array('third_column_id'=>1,'display'=>1,'province_id'=>$provinceList[$i]['id'],'title'=>array('like',array('%大学','%学院'),'OR')))->order(array('order'=>'desc','id'=>'asc'))->limit(12)->select();
		}
//		print_r($provinceList);die;
		$this->assign(array('provinceList'=>$provinceList));
		$this->display();
	}
	//成人高考栏目下的学院列表页某城市获取更多
	public function getMoreSchool(){
		$p_id=I('post.id/d',0);
		$more=M('article_xueli')->field('id,title,hot')->where(array('third_column_id'=>1,'display'=>1,'province_id'=>$p_id,'title'=>array('like',array('%大学','%学院'),'OR')))->order(array('order'=>'desc','id'=>'asc'))->select();
		foreach($more as $k=>$v){
			$more[$k]['url']=U('article',array("id"=>$v["id"]));
			if($v['hot']){
				$more[$k]['hot']=true;
			}else{
				$more[$k]['hot']=false;
			}		
		}
		echo json_encode($more);
	}
	
	
	//成人高考栏目下的专业列表页
	public function major(){
		//各个2级招生专业下的3级栏目
		$majorList=M('third_column')->where(array('second_column_id'=>5,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->select();
//		print_r($majorList);die;
		foreach($majorList as $k=>$v){
			$majorList[$k]['article']=M('article_xueli')->where(array('third_column_id'=>$v['id'],'display'=>1,))->order(array('order'=>'desc','id'=>'asc'))->limit(15)->select();
		}
		$this->assign(array('majorList'=>$majorList));
		$this->display();
	}
	//成人高考栏目下的学院列表页某专业获取更多
	public function getMoreMajor(){
		$m_id=I('post.id/d',0);
		$more=M('article_xueli')->field('id,title,hot')->where(array('third_column_id'=>$m_id,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->select();
		foreach($more as $k=>$v){
			$more[$k]['url']=U('article',array("id"=>$v["id"]));
			if($v['hot']){
				$more[$k]['hot']=true;
			}else{
				$more[$k]['hot']=false;
			}		
		}
		echo json_encode($more);
	}
	
	
	//根据省和专业大类跳转过来的文章列表页
	public function newlist(){
		$type=I('get.type/d',0);
		//类型值为1则是省跳跃过来
		if($type==1){
			$pid=I('get.pid/d',0);
			$province=M('region2')->where(array('id'=>$pid))->getField('name');
			$this->assign(array('title'=>$province));
			$data=M('article_xueli')->field('id,title,hot')->where(array('third_column_id'=>1,'display'=>1,'province_id'=>$pid,'title'=>array('like',array('%大学','%学院'),'OR')))->order(array('order'=>'desc','id'=>'asc'))->select();
		}else if($type==2){ //类型值为2则是大专业类跳跃过来
			$mid=I('get.mid/d',0);
			$major=M('third_column')->where(array('id'=>$mid))->getField('name');
			$this->assign(array('title'=>$major));
			$data=M('article_xueli')->field('id,title,hot')->where(array('third_column_id'=>$mid,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->select();
		}else{
			header("Location:".U('Mobile/Index/go404'));
		}
		$this->assign(array('data'=>$data));
//		print_r($data);die;
		$this->display();
	}
	
	
	//从首页面试求职、职位晋升、复习指导、成考专题跳来的文章列表页面
	public function lists(){
		//1.面试求职   2.职位晋升 3.复习指导  4.成考专题
		$type=I('get.type/d',0);
		if($type==1){ //面试求职
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>8,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else if($type==2){ //职位晋升
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>9,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else if($type==3){ //复习指导
			$reviewSon=M('third_column')->where(array('second_column_id'=>7))->getField('id',true);
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('third_column_id'=>array('IN',$reviewSon),'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else if($type==4){  //成考专题
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>6,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else if($type==5){  //搜索内容
			$keyword=I('get.keyword/s','');
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('first_column_id'=>1,'title'=>array('like',"%{$keyword}%"),'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else{
			header("Location:".U('Mobile/Index/go404'));
		}
		$this->assign(array('data'=>$data));
		$this->display('list');
	}
	//异步获取更多
	public function getMoreList(){
		$type=I('post.type/d',0);
		$num=I('post.num/d',0);
		$keyword=I('post.keyword/s','');
		if($type==1){ //面试求职
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>8,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,5")->select();
		}else if($type==2){ //职位晋升
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>9,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,5")->select();
		}else if($type==3){ //复习指导
			$reviewSon=M('third_column')->where(array('second_column_id'=>7))->getField('id',true);
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('third_column_id'=>array('IN',$reviewSon),'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,5")->select();
		}else if($type==4){  //成考专题
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('second_column_id'=>6,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,5")->select();
		}else if($type==5){  //搜索内容
			$data=M('article_xueli')->field('id,title,subtitle,publish_time,thumb,hot')->where(array('first_column_id'=>1,'title'=>array('like',"%{$keyword}%"),'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,5")->select();
		}
		$newArray=array();
		foreach($data as $k=>$v){
			if(!$v['thumb']){
				$newArray[$k]['style']='style-1';
			}else{
				$newArray[$k]['style']='style-2';
				$newArray[$k]['images']=$v['thumb'];
			}
			$newArray[$k]['title']=$v['title'];
			$newArray[$k]['url']=U('article',array('id'=>$v['id']));
			$newArray[$k]['date']=date('m-d',$v['publish_time']);
		}
		echo json_encode($newArray);
	}
	
	//试题页面 分为专升本，高起点
	public function question(){
		$type=I('get.type/d',0);
		//根据$type判断试题 值为1 为专升本 2为高起点
		if($type==1){
			//4级栏目复习资料下面的专升本
			$data=M('article_xueli')->field('id,title,hot,publish_time')->where(array('fourth_column_id'=>9,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else if($type==2){ 
			$data=M('article_xueli')->field('id,title,hot,publish_time')->where(array('fourth_column_id'=>8,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit(10)->select();
		}else{
			header("Location:".U('Mobile/Index/go404'));
		}
		$this->assign(array('data'=>$data));
		$this->display();
	}
	//试题异步获取更多
	public function getMoreQuestion(){
//		print_r($_POST);
		$arg1=I('post.arg1/d',0);
		$arg2=I('post.arg2/d',0);
		$num=I('post.num/d',0);
		if($arg1==0){
			if($arg2){
				//4级栏目复习资料下面的专升本 单个科目
				$array=array('全部科目','语文','英语','数学','政治','艺术','生态学','民法','教育理论','医学');
				$kemu=$array[$arg2];
				$data=M('article_xueli')->field('id,title,hot,publish_time')->where(array('fourth_column_id'=>9,'display'=>1,'title'=>array('like',"%{$kemu}%")))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,10")->select();
			}else{
				//4级栏目复习资料下面的专升本 所有科目
				$data=M('article_xueli')->field('id,title,hot,publish_time')->where(array('fourth_column_id'=>9,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,10")->select();
			}
		}else{
			if($arg2){
				//4级栏目复习资料下面的高起点 单个科目
				$array=array('全部科目','语文','英语','数学','物理化学','历史地理','俄语/日语');
				$kemu=$array[$arg2];
				$data=M('article_xueli')->field('id,title,hot,publish_time')->where(array('fourth_column_id'=>8,'display'=>1,'title'=>array('like',"%{$kemu}%")))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,10")->select();
			}else{
				//4级栏目复习资料下面的高起点 所有科目
				$data=M('article_xueli')->field('id,title,hot,publish_time')->where(array('fourth_column_id'=>8,'display'=>1))->order(array('order'=>'desc','id'=>'asc'))->limit("$num,10")->select();
			}			
		}
		$newArray=array();
		foreach($data as $k=>$v){
			$newArray[$k]['title']=$v['title'];
			$newArray[$k]['url']=U('article',array('id'=>$v['id']));
			$newArray[$k]['date']=date('m-d',$v['publish_time']);
		}
		echo json_encode($newArray);
	}
}